<template>

    <h2>这是子组件的消息</h2>
    <div>{{ message }}</div>
    <button @click="sendMessage">给父组件发消息</button>
</template>

<script setup>

//钩子函数：defineProps
defineProps({
    message: String,
});

const emit = defineEmits(['message-sent']);
function sendMessage() {
    emit('message-sent', '来自子组件的消息');
}
</script>